﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WeiXinWeb.Models;
using System.Text;
using WeiXinWeb.Services;

namespace WeiXinWeb.Server
{
    public class WeiXinResServer : PSIBaseService
    {
        
        public bool InsertInfo(WeiXinRes model)
        {
            var sql = new StringBuilder("insert tms_weixin_resverimport (id,v_orderID,v_carnumber,v_owner,v_owner_tel,f_owner_price,v_driver,v_driver_tel,d_resver_time,i_isselect,d_lastdt)");
            sql.Append(" values (@id,@orderID,@carnumber,@owner,@ownerTel,@ownerPrice,@driver,@driverTel,@resverTime,@isselect,@lastdt)");
            var p = CreateDbParameters();
            p.AddWithValue("id",model.id);
            p.AddWithValue("orderID",model.orderID);
            p.AddWithValue("carnumber",model.carnumber);
            p.AddWithValue("owner",model.owner);
            p.AddWithValue("ownerTel",model.ownerTel);
            p.AddWithValue("ownerPrice",model.ownerPrice);
            p.AddWithValue("driver", model.driver);
            p.AddWithValue("driverTel", model.driverTel);
            p.AddWithValue("resverTime",model.ResverTime);
            p.AddWithValue("isselect",model.Isselect);
            p.AddWithValue("lastdt", model.LastDt);

           var cc=Execute(sql.ToString(), p);
           if (cc > 0)
               return true;
           else
               return false;
        }


        public List<WeiXinRes> GetImportReseration(string tel)
        {
            var result = new List<WeiXinRes>();
            var sql = new StringBuilder("select * from tms_weixin_resverimport where v_owner_tel=@tel");
            var p = CreateDbParameters();
            p.AddWithValue("tel", tel);

            Query(sql.ToString(), p, reader =>
            {
   
                var temp = new WeiXinRes
                {
                    id = reader.GetGuid(reader.GetOrdinal("id")),
                    orderID = reader.GetGuid(reader.GetOrdinal("v_orderID")),
                    carnumber = reader.GetString(reader.GetOrdinal("v_carnumber")),
                    owner = reader.GetString(reader.GetOrdinal("v_owner")),
                    ownerTel = reader.GetString(reader.GetOrdinal("v_owner_tel")),
                     ownerPrice =reader.GetDecimal(reader.GetOrdinal("f_owner_price")),
                    driver = reader.GetString(reader.GetOrdinal("v_driver")),
                    driverTel = reader.GetString(reader.GetOrdinal("v_driver_tel")),
                    ResverTime = reader.GetDateTime(reader.GetOrdinal("d_resver_time")),
                    ImorOut=0,
                    Isselect = reader.GetInt32(reader.GetOrdinal("i_isselect")),
                    LastDt = reader.GetDateTime(reader.GetOrdinal("d_lastdt"))
                };
                result.Add(temp);
            });
            return result;
        }

        public List<WeiXinRes> GetOutportReseration(string tel)
        {
            var result = new List<WeiXinRes>();
            var sql = new StringBuilder("select * from tms_weixin_resveroutport where v_owner_tel=@tel");
            var p = CreateDbParameters();
            p.AddWithValue("tel", tel);
            Query(sql.ToString(), p, reader =>
            {
                var temp = new WeiXinRes
                {
                    id = reader.GetGuid(reader.GetOrdinal("id")),
                    orderID = reader.GetGuid(reader.GetOrdinal("v_orderID")),
                    carnumber = reader.GetString(reader.GetOrdinal("v_carnumber")),
                    owner = reader.GetString(reader.GetOrdinal("v_owner")),
                    ownerTel = reader.GetString(reader.GetOrdinal("v_owner_tel")),
                    ownerPrice = reader.GetDecimal(reader.GetOrdinal("f_owner_price")),
                    driver = reader.GetString(reader.GetOrdinal("v_driver")),
                    driverTel = reader.GetString(reader.GetOrdinal("v_driver_tel")),
                    ResverTime = reader.GetDateTime(reader.GetOrdinal("d_resver_time")),
                    ImorOut = 1,
                    Isselect = reader.GetInt32(reader.GetOrdinal("i_isselect")),
                    LastDt = reader.GetDateTime(reader.GetOrdinal("d_lastdt")),
                    cntnum = reader.GetString(reader.GetOrdinal("v_cntnum"))
                };
                result.Add(temp);
            });
            return result;
        }

        public bool InsertInfout(WeiXinRes model)
        {
            var sql = new StringBuilder("insert tms_weixin_resveroutport (id,v_orderID,v_carnumber,v_owner,v_owner_tel,f_owner_price,v_driver,v_driver_tel,d_resver_time,i_isselect,v_cntnum,d_lastdt)");
            sql.Append(" values (@id,@orderID,@carnumber,@owner,@ownerTel,@ownerPrice,@driver,@driverTel,@resverTime,@isselect,@cntnum,@lastdt)");
            var p = CreateDbParameters();
            p.AddWithValue("id", model.id);
            p.AddWithValue("orderID", model.orderID);
            p.AddWithValue("carnumber", model.carnumber);
            p.AddWithValue("owner", model.owner);
            p.AddWithValue("ownerTel", model.ownerTel);
            p.AddWithValue("ownerPrice", model.ownerPrice);
            p.AddWithValue("driver", model.driver);
            p.AddWithValue("driverTel", model.driverTel);
            p.AddWithValue("resverTime", model.ResverTime);
            p.AddWithValue("isselect", model.Isselect);
            p.AddWithValue("cntnum", model.cntnum);
            p.AddWithValue("lastdt", model.LastDt);
            var cc = Execute(sql.ToString(), p);
            if (cc > 0)
                return true;
            else
                return false;
        }
    }
}